package com.trex.lwlsh.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Create by Trex on 2018/1/13
 */
public class LogUtil {
    public static  String path=ReadConfigUtil.readconfig("path");//定义你的工作存储地址

    /**
     *
     * @param log
     * @throws IOException
     */
    public static  void logs( String log) throws IOException {
        System.out.println("==========================================================");
        System.out.println(new ActionUtil().time("[yyyy-MM-dd HH:mm:ss]-| ")+log);
        System.out.println("==========================================================");
    }

    /**
     *错误日志保存
     * @param e
     */
    public static void saveELog(Exception e) {
        try {

            File file = new File( path+"Log" + File.separator + new ActionUtil().time("yyyyMMddHHmss")  + ".txt" );
            PrintWriter writer = null;
            FileWriter fileWrite = new FileWriter(file, true);
            writer = new PrintWriter(fileWrite);
            writer.append(System.getProperty("line.separator")
                    + new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss")
                    .format(new Date()) + "__" );
            writer.append(System.getProperty("line.separator"));
            writer.append("      *************************" + e.toString()
                    + "*************************");
            writer.append(System.getProperty("line.separator"));
            e.printStackTrace(writer);
            writer.flush();
            writer.close();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

}
